//InstancedOrbs.h
//Created 03/05/14
//Created By Daniel Bowler
//
//Second attempt at making the orbs (rendering) class. This time, we will just
//use the engines own StaticInstanced class since we do not need a custom
//shader (refraction looks shit tbh. Reflections is available at engine level
//as is transparancy). 
//
// Edited: 18/05/14
// Added bounding box collision detection

#pragma once

//Include std vector class
#include <vector>

//Inherit from AbstractModel
#include "AbstractModel.h"

//Include Maths helper (which will include XNA maths)
#include "MathHelper.h"

// Include collision manager to handle hitboxes
#include "CollisionManager.h"


//Forward declare the ID3D11Device. 
struct ID3D11Device;

//Forward declare StaticInstancedModel - this class provides an interface
//to this. 
class StaticInstancedModel;

//Forward declare graphics interface -  a function will add this model
//to the batch
class GraphicsInterface;

//Define that control the size of the orb. 
#define INST_ORB_RADIUS 1.5f
//Define that controls the (init time) tesselation of the sphere. 
#define INST_ORB_STACK_COUNT 15
#define INST_ORB_SLICE_COUNT 15

//How much to displace the orbs above the terrain?
#define INST_ORB_DISPLACEMENT_Y 3.0f

class InstancedOrbs : public AbstractModel
{
public:
	//Default constructor - takes the initial numnber of orbs in the scene as
	//a paramater along with the D3D device. 
	InstancedOrbs(ID3D11Device* device, unsigned initialCount);
	//Default destructor - cleans up D3D resources
	~InstancedOrbs();

public:
	//Sets the orbs locations - its your responsability to set the Y location 
	//based on the terrains height (Use the Terrains own function) - though
	//this class will displace the orb on the Y axis based on the #define.
	void SetOrbLocations(const std::vector<XMFLOAT3>&locations);

	//Update an instances location and if active (rendered).
	void UpdateInstance(unsigned instanceID, 
		XMFLOAT3 position, bool isActive);

public:
	//Returns the position of an instance
	XMFLOAT3 GetInstancePosition(unsigned instanceID);

public:
	//Adds the model to the GraphicsInterface batch. Called each frame in the
	//scenes Render() function. (Override)
	void AddToBatch(GraphicsInterface* gi);

private:
	//Pointer to our StaticInstancedModel objecr
	StaticInstancedModel* instOrbs;


// ----------------------------- EDIT --------------------------------
private:
	// Hitbox used for collision detection
	std::vector<AABB> HitBox;

public:
	// Returns hitbox for collision detection
	AABB GetHitBox(unsigned instanceID);

	// Returns whether the current instance is active or not.
	bool GetIsActive(unsigned instanceID);

	//sets is active for a spesific instance using id
	void SetIsActive(unsigned instanceID,bool active);
};